class CopyrightWebpacPlugin {
  constructor(props) {
    // 接收实例化插件时的参数
    // console.log(props);
  }
 
  apply(compiler) {
    // compiler 为webpack的实例
    //hooks: https://webpack.js.org/api/compiler-hooks/

    // emit: 当把打包代码放到dist之前, AsyncSeriesHook 异步钩子
    compiler.hooks.emit.tapAsync('CopyrightWebpacPlugin', (compilation, cb) => {
      // compilation 存放了这次打包的所有内容
      console.log(compilation.assets);
      debugger;
      
      compilation.assets['copyright.txt'] = {
        source: function() {
          // 内容
          return 'copyright by a'
        },
        size: function() {
          // 文件为14字符长度
          return 14;
        }
      }
      
      cb();
    });

    // compile: 同步钩子, 直接tap
    compiler.hooks.compile.tap('CopyrightWebpacPlugin', (compilation) => {
      console.log('compiler');
    });
  }
}

module.exports = CopyrightWebpacPlugin;